﻿using Maxi.Models.Banco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Maxi.Models
{
    public class RegisterLog : ActionFilterAttribute, IActionFilter
    {
        //public String Descricao { get; set; }

        //public RegisterLog(String descricao)
        //{
        //    Descricao = descricao;
        //}

        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
            var c = new Conexao();

            var log = new Tb_LogSistema()
            {
                Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                Action = filterContext.ActionDescriptor.ActionName,
                Ip = filterContext.HttpContext.Request.UserHostAddress,
                Data = filterContext.HttpContext.Timestamp
                //Usuario = 1
            };

            c.Tb_LogSistema.Add(log);
            c.SaveChanges();

            this.OnActionExecuting(filterContext);
        }
    }
}